clear
set more off
log close

log using "Perspectives_Clean.txt", text replace

*Aaron Rosenthal
*Do File
*Perspectives on Politics- Submerged for Some?

*Reading in data- using 2016 ANES Time Series Data

use anes_timeseries_2016.dta, clear

**********************
***CODING VARIABLES***
**********************

*Race
gen white=.
replace white=1 if V161310x==1
replace white=0 if V161310x==2 | V161310x==3 | V161310x==4 | V161310x==5 | V161310x==6

label define white 0 "People of Color" 1 "White" 
label values white white

gen black=.
replace black=1 if V161310x==2
replace black=0 if V161310x==1 | V161310x==3 | V161310x==4 | V161310x==5 | V161310x==6

*Gender
gen female=.
replace female=1 if V161342==2
replace female=0 if V161342==1

*Income
gen income=V161361x
recode income -9 -5 = .

gen income1=(income-1)/27
drop income
rename income1 income

*Party ID
gen partyid=V161158x
recode partyid -9 -8 = .

gen partyid1=(partyid-1)/6
drop partyid
rename partyid1 partyid

*Ideology
gen ideology=.
replace ideology=1 if V161126==1 | V161126==2 | V161126==3 | V161127==1
replace ideology=3 if V161126==5 | V161126==6 | V161126==7 | V161127==2
replace ideology=2 if V161126==4 | V161127==3

gen ideology1=(ideology-1)/2
drop ideology
rename ideology1 ideology

*Education
gen educ=V161270
recode educ 95 -9 = .
recode educ 12 = 11
recode educ 13 = 12
recode educ 14 = 13
recode educ 15 = 14
recode educ 16 = 14
recode educ 90 = 9

gen educ1=(educ-1)/13
drop educ
rename educ1 educ

*Age
gen age=V161267x
recode age -1 = .

gen age1=(age-1)/12
drop age
rename age1 age

*Political knowledge
recode V161513 -9 -5 = .
gen pol_knowl1=.
replace pol_knowl1=1 if V161513==6
replace pol_knowl1=0 if V161513<6 & V161513!=.
replace pol_knowl1=0 if V161513>6 & V161513!=.

gen pol_knowl2=.
replace pol_knowl2=1 if V161514==1
replace pol_knowl2=0 if V161514==2 | V161514==3 | V161514==4

gen pol_knowl3=.
replace pol_knowl3=1 if V161515==2 
replace pol_knowl3=0 if V161515==1 

gen pol_knowl4=.
replace pol_knowl4=1 if V161516==2 
replace pol_knowl4=0 if V161516==1 

gen pol_knowl=pol_knowl1+pol_knowl2+pol_knowl3+pol_knowl4

gen pol_knowl10=pol_knowl/4
drop pol_knowl
rename pol_knowl10 pol_knowl

*Religiosity
gen religiosity=.
replace religiosity=1 if V161241==1
replace religiosity=0 if V161241==2

*Police Feeling thermometer
gen police_FT=V162110
recode police_FT 999 998 -9 -7 -6 = .

gen police_FT1=police_FT/100
drop police_FT
rename police_FT1 police_FT

*Welfare Spending
gen spending_welfare=.
replace spending_welfare=0 if V161209==2
replace spending_welfare=1 if V161209==3
replace spending_welfare=2 if V161209==1

gen spending_welfare1=spending_welfare/2
drop spending_welfare
rename spending_welfare1 spending_welfare

*Social security Spending
gen spending_socsec=.
replace spending_socsec=0 if V161205==2
replace spending_socsec=1 if V161205==3
replace spending_socsec=2 if V161205==1

gen spending_socsec1=spending_socsec/2
drop spending_socsec
rename spending_socsec1 spending_socsec

*Protecting the environment spending
gen spending_environ=.
replace spending_environ=0 if V161212==2
replace spending_environ=1 if V161212==3
replace spending_environ=2 if V161212==1

gen spending_environ1=spending_environ/2
drop spending_environ
rename spending_environ1 spending_environ

*Child care spending
gen spending_chicare=.
replace spending_chicare=0 if V161210==2
replace spending_chicare=1 if V161210==3
replace spending_chicare=2 if V161210==1
tab spending_chicare

gen spending_chicare1=spending_chicare/2
drop spending_chicare
rename spending_chicare1 spending_chicare

*Trust government to do what’s right
gen trust_right=.
replace trust_right=0 if V161215==5
replace trust_right=.25 if V161215==4
replace trust_right=.5 if V161215==3
replace trust_right=.75 if V161215==2
replace trust_right=1 if V161215==1

*Generating ordered trust right to run with ordered logit (Table C2)
gen trust_right_ordered=trust_right
recode trust_right_ordered .25=1 .5=2 .75=3 1=4


**********************
*******ANALYSIS*******
**********************

*SURVEY SETTING DATA
	svyset [pweight= V160102]

*Models

	*Table 1
	*Model 1.1
	svy: reg trust_right partyid ideology female age income educ pol_knowl religiosity white spending_welfare 

	*Model 1.2	
	svy: reg trust_right partyid ideology female age income educ pol_knowl religiosity white##c.spending_welfare
	
	*Model 1.3
	svy: reg trust_right partyid ideology female age income educ pol_knowl religiosity white police_FT

	*Model 1.4	
	svy: reg trust_right partyid ideology female age income educ pol_knowl religiosity white##c.police_FT	
	
*Figures

	*Mean values for graphs
		*Partyid=.5
		*Ideology=.55
		*Female=1
		*Age=.5
		*Income=.54
		*Education=.72
		*Political Knowledge=.52
	
	*Figure 1
	svy: reg trust_right partyid ideology female age income educ pol_knowl religiosity white##c.spending_welfare
	margins, predict() at(spending_welfare=(0(.5)1) white=(0 1) partyid=.5 ideology=.55 female=1 age=.5 income=.54 	educ=.72 pol_knowl=.52)
	marginsplot, ytitle(Predicted Level of Political Trust) ylabel(0(.1).5) title("") ///
	xtitle(Welfare Spending Attitudes, size(medsmall)) xlabel(.02 "Decreased" .5 "Kept the Same" .98 "Increased", labsize(small) noticks) ///
	caption("All other independent variables are held at their means or modes. Source: ANES 2016.", size(vsmall)) graphregion(fcolor(white)) ///
	note("Slopes are statistically different at p=.049. 95% confidence intervals shown.", size(vsmall)) ysize(8) xsize(8) scheme(s1mono)
	
	*Figure 2
	svy: reg trust_right partyid ideology female age income educ pol_knowl religiosity white##c.police_FT
	margins, predict() at(police_FT=(0(.5)1) white=(0 1)) atmeans
	marginsplot, ytitle(Predicted Level of Political Trust) ylabel(0(.1).5) title("") ///
	xtitle(Police Attitudes, size(medsmall)) xlabel(.02 "Negative" .5 "Neutral" .98 "Positive", labsize(small) noticks) ///
	caption("All other independent variables are held at their means or modes. Source: ANES 2016.", size(vsmall)) graphregion(fcolor(white)) ///
	note("Slopes are statistically different at p=.048. 95% confidence intervals shown.", size(vsmall)) ysize(8) xsize(8) scheme(s1mono)
	

*Appendix Models

	*Table C1- Models run with ordinal logit
	*Model C1.1
	svy: ologit trust_right_ordered partyid ideology female age income educ pol_knowl religiosity white spending_welfare

	*Model C1.2	
	svy: ologit trust_right_ordered partyid ideology female age income educ pol_knowl religiosity white##c.spending_welfare	

	*Model C1.3	
	svy: ologit trust_right_ordered partyid ideology female age income educ pol_knowl religiosity white police_FT

	*Model C1.4	
	svy: ologit trust_right_ordered partyid ideology female age income educ pol_knowl religiosity white##c.police_FT	

	*Table C2- Placebo tests
	*Model C2.1
	svy: reg trust_right partyid ideology female age income educ pol_knowl religiosity white##c.spending_socsec	

	*Model C2.2
	svy: reg trust_right partyid ideology female age income educ pol_knowl religiosity white##c.spending_chicare	

	*Model C2.3
	svy: reg trust_right partyid ideology female age income educ pol_knowl religiosity white##c.spending_environ	
		
	
	*Table C3- Running interactions with Party ID
	*Model C3.1
	svy: reg trust_right ideology female age income educ pol_knowl religiosity white c.partyid##c.spending_welfare
	
	*Model C3.2
	svy: reg trust_right ideology female age income educ pol_knowl religiosity white c.partyid##c.police_FT
	
